/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * Exclui.java
 *
 * Created on 16/11/2011, 21:21:34
 */
package gerenciadorescola.view;

import gerenciadorescola.model.pattern.facade.Fachada;
import java.awt.Image;
import java.awt.Toolkit;
import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.swing.JOptionPane;

/**
 *
 * @author Pedro Freitas
 */
public class Exclui extends javax.swing.JFrame {

    /** Creates new form Exclui */
    public Exclui() {
        initComponents();
        try {
            Image icon = Toolkit.getDefaultToolkit().getImage("src/gerenciadorescola/imagens/uff.png");
            setIconImage(icon);
        } catch (Exception e) {
            e.getStackTrace();
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jTabbedPane1 = new javax.swing.JTabbedPane();
        jPanel2 = new javax.swing.JPanel();
        codTLabel = new javax.swing.JLabel();
        codTText = new javax.swing.JTextField();
        excluirTButton = new javax.swing.JButton();
        voltarTButton = new javax.swing.JButton();
        jPanel3 = new javax.swing.JPanel();
        codALabel = new javax.swing.JLabel();
        codAText = new javax.swing.JTextField();
        excluirAButton = new javax.swing.JButton();
        voltarAButton = new javax.swing.JButton();
        codTurmaALabel = new javax.swing.JLabel();
        codTurmaAText = new javax.swing.JTextField();
        jPanel1 = new javax.swing.JPanel();
        jPanel4 = new javax.swing.JPanel();
        profRadioButton = new javax.swing.JRadioButton();
        dirRadioButton = new javax.swing.JRadioButton();
        codFLabel = new javax.swing.JLabel();
        codFText = new javax.swing.JTextField();
        excluirFButton = new javax.swing.JButton();
        voltarFButton = new javax.swing.JButton();
        codTurmaLabel = new javax.swing.JLabel();
        codTurmaText = new javax.swing.JTextField();

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setTitle("Exclui - Escola TPA");

        codTLabel.setText("Código :");

        excluirTButton.setText("Excluir");
        excluirTButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirTButtonActionPerformed(evt);
            }
        });

        voltarTButton.setText("Voltar");
        voltarTButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarTButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(codTLabel)
                .addGap(10, 10, 10)
                .addComponent(codTText, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(196, Short.MAX_VALUE))
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(243, Short.MAX_VALUE)
                .addComponent(excluirTButton)
                .addGap(18, 18, 18)
                .addComponent(voltarTButton)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addGap(50, 50, 50)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(codTLabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 50, Short.MAX_VALUE)
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(excluirTButton)
                    .addComponent(voltarTButton))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Turma", jPanel2);

        codALabel.setText("Código :");

        excluirAButton.setText("Excluir");
        excluirAButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirAButtonActionPerformed(evt);
            }
        });

        voltarAButton.setText("Voltar");
        voltarAButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarAButtonActionPerformed(evt);
            }
        });

        codTurmaALabel.setText("Turma :");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addComponent(excluirAButton)
                        .addGap(18, 18, 18))
                    .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                        .addContainerGap()
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addComponent(codTurmaALabel)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(codTurmaAText))
                            .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel3Layout.createSequentialGroup()
                                .addComponent(codALabel)
                                .addGap(10, 10, 10)
                                .addComponent(codAText, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE)))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 125, Short.MAX_VALUE)))
                .addComponent(voltarAButton)
                .addContainerGap())
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(37, 37, 37)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codAText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(codALabel))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTurmaALabel)
                    .addComponent(codTurmaAText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(25, 25, 25)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(voltarAButton)
                    .addComponent(excluirAButton))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Aluno", jPanel3);

        jPanel4.setBorder(javax.swing.BorderFactory.createEtchedBorder());

        buttonGroup1.add(profRadioButton);
        profRadioButton.setText("Professor");
        profRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                profRadioButtonActionPerformed(evt);
            }
        });

        buttonGroup1.add(dirRadioButton);
        dirRadioButton.setText("Diretor");
        dirRadioButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                dirRadioButtonActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(profRadioButton)
                .addGap(92, 92, 92)
                .addComponent(dirRadioButton)
                .addContainerGap(149, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                .addComponent(profRadioButton)
                .addComponent(dirRadioButton))
        );

        codFLabel.setText("Código :");

        excluirFButton.setText("Excluir");
        excluirFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                excluirFButtonActionPerformed(evt);
            }
        });

        voltarFButton.setText("Voltar");
        voltarFButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                voltarFButtonActionPerformed(evt);
            }
        });

        codTurmaLabel.setText("Turma :");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                        .addComponent(excluirFButton)
                        .addGap(18, 18, 18)
                        .addComponent(voltarFButton))
                    .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(codTurmaLabel)
                            .addGap(18, 18, 18)
                            .addComponent(codTurmaText))
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, jPanel1Layout.createSequentialGroup()
                            .addComponent(codFLabel)
                            .addGap(18, 18, 18)
                            .addComponent(codFText, javax.swing.GroupLayout.PREFERRED_SIZE, 139, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                    .addComponent(codFLabel)
                    .addComponent(codFText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(codTurmaLabel)
                    .addComponent(codTurmaText, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(voltarFButton)
                    .addComponent(excluirFButton))
                .addContainerGap())
        );

        jTabbedPane1.addTab("Funcionário", jPanel1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 400, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jTabbedPane1, javax.swing.GroupLayout.Alignment.TRAILING)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void voltarTButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarTButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_voltarTButtonActionPerformed

    private void voltarAButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarAButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_voltarAButtonActionPerformed

    private void voltarFButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_voltarFButtonActionPerformed
        this.dispose();
    }//GEN-LAST:event_voltarFButtonActionPerformed

    private void excluirTButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirTButtonActionPerformed
        Map<String, String> entrada = new HashMap();
        entrada.put("codigo", codTText.getText());
        Map<String, String> saida = null;
        try {
            saida = Fachada.ComandoExcluiTurma(entrada);
        } catch (Exception ex) {
            Logger.getLogger(Exclui.class.getName()).log(Level.SEVERE, null, ex);
        }
        JOptionPane.showMessageDialog(rootPane, saida.get("msg"));

        codTText.setText("");
    }//GEN-LAST:event_excluirTButtonActionPerformed

    private void excluirAButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirAButtonActionPerformed
        Map<String, String> entrada = new HashMap();
        entrada.put("codigo", codFText.getText());
        entrada.put("codTurma", codTurmaText.getText());
        Map<String, String> saida = new HashMap();

        try {
            saida = Fachada.ComandoExcluiAluno(entrada);
        } catch (Exception ex) {
            Logger.getLogger(Exclui.class.getName()).log(Level.SEVERE, null, ex);
        }
        JOptionPane.showMessageDialog(rootPane, saida.get("msg"));


        codAText.setText("");
        codTurmaAText.setText("");
    }//GEN-LAST:event_excluirAButtonActionPerformed

    private void excluirFButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_excluirFButtonActionPerformed
        Map<String, String> saida = new HashMap();
        if (dirRadioButton.isSelected()) {

            try {
                saida = Fachada.ComandoExcluiDiretor(null);
            } catch (Exception ex) {
                Logger.getLogger(Exclui.class.getName()).log(Level.SEVERE, null, ex);
            }
            JOptionPane.showMessageDialog(rootPane, saida.get("msg"));

        } else if (profRadioButton.isSelected()) {

            Map<String, String> entrada = new HashMap();
            entrada.put("codigo", codFText.getText());
            entrada.put("codTurma", codTurmaText.getText());

            try {
                saida = Fachada.ComandoExcluiProfessor(entrada);
            } catch (Exception ex) {
                Logger.getLogger(Exclui.class.getName()).log(Level.SEVERE, null, ex);
            }
            JOptionPane.showMessageDialog(rootPane, saida.get("msg"));


        } else {
            JOptionPane.showMessageDialog(rootPane, "Selecione um tipo de funcionário!");

        }

        buttonGroup1.clearSelection();
        codFText.setText("");
        codTurmaText.setText("");
    }//GEN-LAST:event_excluirFButtonActionPerformed

    private void dirRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_dirRadioButtonActionPerformed
        codFLabel.setVisible(false);
        codFText.setVisible(false);
        codTurmaLabel.setVisible(false);
        codTurmaText.setVisible(false);
    }//GEN-LAST:event_dirRadioButtonActionPerformed

    private void profRadioButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_profRadioButtonActionPerformed
        codFLabel.setVisible(true);
        codFText.setVisible(true);
    }//GEN-LAST:event_profRadioButtonActionPerformed

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Exclui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Exclui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Exclui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Exclui.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                new Exclui().setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JLabel codALabel;
    private javax.swing.JTextField codAText;
    private javax.swing.JLabel codFLabel;
    private javax.swing.JTextField codFText;
    private javax.swing.JLabel codTLabel;
    private javax.swing.JTextField codTText;
    private javax.swing.JLabel codTurmaALabel;
    private javax.swing.JTextField codTurmaAText;
    private javax.swing.JLabel codTurmaLabel;
    private javax.swing.JTextField codTurmaText;
    private javax.swing.JRadioButton dirRadioButton;
    private javax.swing.JButton excluirAButton;
    private javax.swing.JButton excluirFButton;
    private javax.swing.JButton excluirTButton;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JTabbedPane jTabbedPane1;
    private javax.swing.JRadioButton profRadioButton;
    private javax.swing.JButton voltarAButton;
    private javax.swing.JButton voltarFButton;
    private javax.swing.JButton voltarTButton;
    // End of variables declaration//GEN-END:variables
}
